﻿unit GetUserFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,  JvFormPlacement, JvComponentBase, JvAppStorage,
  JvAppIniStorage, JvXPBar, JvExControls, JvXPCore, JvXPContainer, GridsEh,
  DBGridEh, ComCtrls, JvExComCtrls, JvComCtrls, ExtCtrls, JvExExtCtrls,
  JvExtComponent, JvSplit, DB, JvXPButtons, Grids, DBGrids, FIBSQLMonitor,
  StdCtrls, CheckLst, DBCtrls, FIBDataSet, pFIBDataSet, JvExStdCtrls, JvEdit,
  DBGridEhGrouping;

type
  TGetUserForm = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Grid: TDBGridEh;
    Label1: TLabel;
    Psw: TJvEdit;
    JvXPButton1: TJvXPButton;
    JvXPButton2: TJvXPButton;
    DS: TpFIBDataSet;
    DataSource: TDataSource;
    Storage: TJvFormStorage;
    AppIni: TJvAppIniFileStorage;
    procedure GridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure JvXPButton1Click(Sender: TObject);
    procedure PswKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure StorageAfterRestorePlacement(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
  private
    fShablon: string;
    function ScanPassword: boolean;
    procedure SetShablon(const Value: string);
  public
    property Shablon: string read fShablon write SetShablon;
  end;


var
  GetUserForm: TGetUserForm;

implementation

uses common, DModule, cmUtils;

 {$R *.dfm}

//--------------------------GetUserForm-----------------------------------------
procedure TGetUserForm.FormCreate(Sender: TObject);
begin
 DS.Database:=MainDb;
 DS.Transaction:=MainDb.DefaultTransaction;
 DS.Open;
end;

procedure TGetUserForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 case Key of
  VK_ESCAPE: ModalResult:=mrCancel; 
 end;
end;

procedure TGetUserForm.GridKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 case Key of
  VK_RETURN: ActiveControl:=Psw;
 end;
end;

procedure TGetUserForm.JvXPButton1Click(Sender: TObject);
begin
 if ScanPassword then
 begin
  IsChief:=Copy(DS.FN('PROFILES').AsString,2,1)='1';
  fProfiles:=DS.FN('PROFILES').AsString;
  UserCod:=DS.FN('Code').AsString;
  ModalResult:=mrOk
 end
 else begin
       ModalResult:=mrNone;
       ShowMessage('Ошибка при вводе пароля.');
      end;
end;

procedure TGetUserForm.PswKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 case Key of
  VK_RETURN: JvXPButton1Click(nil);
 end;
end;

function TGetUserForm.ScanPassword: boolean;
begin
 if DS.IsEmpty then Result:=true
 else Result:=DS.FN('Psw').AsString=Psw.Text;
 if not DS.IsEmpty then Psw.Tag:=DS.FN('Code').AsInteger;
end;

procedure TGetUserForm.SetShablon(const Value: string);
begin
 fShablon := Value;
 if fShablon<>'' then
   DS.Conditions.AddCondition('Shb','Profiles LIKE '#39+fShablon+#39, true);
 DS.ApplyConditions(true);
end;

procedure TGetUserForm.StorageAfterRestorePlacement(Sender: TObject);
begin
 DS.Locate('Code',Psw.Tag, []);
end;

end.
